package com.example.network;

import android.content.Context;

import com.example.base.BaseApplication;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.callback.RequestCallBack;

/**
 * 
 * 作者: Rose 
 * 业务名:联网业务 
 * 功能说明: 联网下载数据封装类 
 * 编写日期: 2014-12-4
 * 
 */
public class ProtocolService {

	private static Context context = BaseApplication.getApplication()
			.getApplicationContext();

	public static void initConfig(Context mContext) {
		context = mContext;
	}

	
	/**
	 * 
	 * 作   者：dong
	 * 方法说明：登录
	 * @param handler
	 */
	public static void login(String userName, String pwd,
			RequestCallBack<String> handler) {
		String url = ProtocolConst.LOGIN+"?";
		url = urlAdd(url,"username", userName);
		url = urlAdd(url,"pwd", pwd);
		VtionHttpClient.get(url , handler);
	}

	/**
	 * 
	 * 作   者：Rose
	 * 方法说明：注册
	 * @param handler
	 */
	public static void register(String deciceid ,String userName, String pwd,String tel,String mail,
			RequestCallBack<String> handler) {
		String url = ProtocolConst.REGISTER+"?";
		url = urlAdd(url,"deviceid", deciceid);
		url = urlAdd(url,"username", userName);
		url = urlAdd(url,"pwd", pwd);
		url = urlAdd(url,"usertel", tel);
		url = urlAdd(url,"useremail", mail);
		VtionHttpClient.get(url , handler);
	}
	
	/**
	 * 作   者：Rose
	 * 方法说明：获取咨询
	 * @param intStartIndex
	 * @param intPageSize
	 * @param NewsType
	 * @param handler
	 */
	public static void newsList(String intStartIndex, String intPageSize,String NewsType,
			RequestCallBack<String> handler) {
		String url = ProtocolConst.GET_ZIXUN_LIST+"?";
		url = urlAdd(url,"intStartIndex", intStartIndex);
		url = urlAdd(url,"intPageSize", intPageSize);
		url = urlAdd(url,"NewsType", NewsType);
		VtionHttpClient.get(url , handler);
	}
	
	/**
	 * 作   者：dong
	 * 方法说明：添加收藏
	 * @param handler
	 */
	public static void collectAdd(String userid, String newsid,String newstitle,
			RequestCallBack<String> handler) {
		String url = ProtocolConst.COLLECTADD+"?";
		url = urlAdd(url,"UserId", userid);
		url = urlAdd(url,"NewsId", newsid);
		url = urlAdd(url,"NewsTitle", newstitle);
		VtionHttpClient.get(url , handler);
	}
	
	/**
	 * 作   者：dong
	 * 方法说明：收藏列表
	 * @param handler
	 */
	public static void collectList(String userid, String newsid,String inStartIndex,String intPageSize,
			RequestCallBack<String> handler) {
		String url = ProtocolConst.COLLECTLIST+"?";
		url = urlAdd(url,"UserId", userid);
		url = urlAdd(url,"NewsId", newsid);
		url = urlAdd(url,"inStartIndex", inStartIndex);
		url = urlAdd(url,"intPageSize", intPageSize);
		VtionHttpClient.get(url , handler);
	}
	
	/**
	 * 作   者：dong
	 * 方法说明：资讯详情
	 * @param handler
	 */
	public static void zixunDetil(String autoID,
			RequestCallBack<String> handler) {
		String url = ProtocolConst.GET_ZIXUN_DETIL+"?";
		url = urlAdd(url,"autoID", autoID);
		VtionHttpClient.get(url , handler);
	}
	
	/**
	 * 作   者：dong
	 * 方法说明：分享或点击
	 * @param handler
	 */
	public static void share(String autoID,
			RequestCallBack<String> handler) {
		String url = ProtocolConst.GET_ZIXUN_SHARE+"?";
		url = urlAdd(url,"autoID", autoID);
		VtionHttpClient.get(url , handler);
	}
	/**
	 * 作   者：dong
	 * 方法说明：关于我们
	 * @param handler
	 */
	public static void about(
			RequestCallBack<String> handler) {
		String url = ProtocolConst.ABOUTUS+"?";
		VtionHttpClient.get(url , handler);
	}
	/**
	 * 作   者：dong
	 * 方法说明：获取图片
	 * @param handler
	 */
	public static void image(String imageType,
			RequestCallBack<String> handler) {
		String url = ProtocolConst.GET_IMAGE_LIST+"?";
		url = urlAdd(url,"imageType",imageType);
		VtionHttpClient.get(url , handler);
	}
	
	/**
	 * 作   者：dong
	 * 方法说明：申请留学
	 * @param handler
	 */
	public static void modify(String autoID,String UserName,String Pwd,String DeviceId,String TrueName,
			String UserSex,String UserBorn,String UserTel,String UserEmal, String UserQQ,
			String UserSchool,String userProvince,String UserProfessional,String UserGrade,
			String UserInfo,String IELTS,String TOEFLIBT,String GRE,String SAT,String WantCount,
			String WantSchool,String WantProfessional,String WantPrice,String UserResource,
			String DealingDatetime,String AskDatetime,String AskOwn,String Remark,String AddTime,
			RequestCallBack<String> handler) {
		String url = ProtocolConst.MODIFY+"?";
		url = urlAdd(url,"autoID", autoID);
		url = urlAdd(url,"UserName", autoID);
		url = urlAdd(url,"Pwd", autoID);
		url = urlAdd(url,"DeviceId", autoID);
		url = urlAdd(url,"TrueName", autoID);
		url = urlAdd(url,"UserSex", autoID);
		url = urlAdd(url,"UserBorn", autoID);
		url = urlAdd(url,"UserTel", autoID);
		url = urlAdd(url,"UserEmal", autoID);
		url = urlAdd(url,"UserSchool", autoID);
		url = urlAdd(url,"userProvince", autoID);
		url = urlAdd(url,"UserProfessional", autoID);
		url = urlAdd(url,"UserGrade", autoID);
		url = urlAdd(url,"UserInfo", autoID);
		url = urlAdd(url,"IELTS", autoID);
		url = urlAdd(url,"UserInfo", autoID);
		url = urlAdd(url,"TOEFLIBT", autoID);
		url = urlAdd(url,"GRE", autoID);
		url = urlAdd(url,"SAT", autoID);
		url = urlAdd(url,"WantCount", autoID);
		url = urlAdd(url,"WantSchool", autoID);
		url = urlAdd(url,"WantProfessional", autoID);
		url = urlAdd(url,"WantPrice", autoID);
		url = urlAdd(url,"UserResource", autoID);
		url = urlAdd(url,"DealingDatetime", autoID);
		url = urlAdd(url,"AskDatetime", autoID);
		url = urlAdd(url,"AskOwn", autoID);
		url = urlAdd(url,"Remark", autoID);
		url = urlAdd(url,"AddTime", autoID);
		VtionHttpClient.get(url , handler);
	}
	
	/**
	 * 作   者：Rose
	 * 方法说明：统一获取get请求url的拼接
	 * @param url	原url
	 * @param key	要拼接的参数名
	 * @param value	要拼接的参数值
	 * @return   每次返回拼接一个参数后的url
	 */
	private static String urlAdd(String url ,String key ,String value){
		url = url+"&"+key+"="+value;
		return url;
	}
}
